package com.digua.base.util

import com.blankj.utilcode.util.ConvertUtils
import com.blankj.utilcode.util.EncryptUtils

object RSAUtil {

    fun encryptRSA2HexString(data: String, publicKey: String): String {
        val dataByte = data.toByteArray(Charsets.UTF_8)
        val pubKey = publicKey.toByteArray(Charsets.UTF_8)
        return EncryptUtils.encryptRSA2HexString(dataByte, pubKey, 1024, "RSA/None/PKCS1Padding")
    }

    fun encryptRSA2Base64(data: String, publicKey: String): String {
        val dataByte = data.toByteArray(Charsets.UTF_8)
        val pubKey = publicKey.toByteArray(Charsets.UTF_8)
        val bytes = EncryptUtils.encryptRSA2Base64(dataByte, pubKey, 1024, "RSA/None/PKCS1Padding")
        return ConvertUtils.bytes2HexString(bytes)
    }

    fun encryptRSA2Base64(data: String, pubKey: ByteArray): String {
        val dataByte = data.toByteArray(Charsets.UTF_8)
        val bytes = EncryptUtils.encryptRSA2Base64(dataByte, pubKey, 1024, "RSA/None/PKCS1Padding")
        return ConvertUtils.bytes2HexString(bytes)
    }

}